package android.framework.reflaction.injectors;

import java.lang.reflect.Field;

import roboguice.inject.InjectView;
import android.view.View;

public class FieldInjector implements IReflactionInjector{

	public void Inject(View view, Object obj) {
		Class<?> cls = obj.getClass();
		
		for (Field field : ReflactionHelper.getAllFields(cls)) {
			InjectView annotation = field.getAnnotation(InjectView.class);
			if(annotation != null){
				int value = annotation.value();
				View v = view.findViewById(value);
				try {
					field.setAccessible(true);
					field.set(obj, v);
				} catch (Exception e) {
					throw new RuntimeException("can't inject to field: " + field.getName(), e);
				}	
			}
		}
	}

}
